package com.beiing.tianshuai.tianshuai.huodong.model;

import com.beiing.tianshuai.tianshuai.entity.EventTypesBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Description :
 *
 * @author Jinda Yang
 * @date 2018/5/30
 */
public class EventsModel implements EventsModelImpl{

    private static final String TAG = "EventsModel";
    private OnResponseListener mListener;

    public EventsModel(OnResponseListener listener) {
        mListener = listener;
    }

    @Override
    public void getEventTypes(String uid) {
        DisposableObserver<EventTypesBean> observer = new DisposableObserver<EventTypesBean>() {
            @Override
            public void onNext(EventTypesBean bean) {
                if (mListener != null) {
                    mListener.onGetEventTypesSuccess(bean);
                }
            }

            @Override
            public void onError(Throwable e) {
                if (mListener != null) {
                    mListener.onGetEventTypesError(e);
                }
            }

            @Override
            public void onComplete() {
                LogUtils.i("获取活动分类请求结束", TAG);
            }
        };
        DataManager.getEventTypes(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public interface OnResponseListener {

        /**
         * 获取活动分类成功
         *
         * @param bean 活动分类数据实体
         */
        void onGetEventTypesSuccess(EventTypesBean bean);

        /**
         * 获取活动分类请求异常
         *
         * @param throwable 异常
         */
        void onGetEventTypesError(Throwable throwable);
    }
}
